package Text15;

import java.util.*;

public class Main {
    static int N = 210;
    static int[] w = new int[2 * N];
    static int[] s = new int[2 * N];
    static int[][] f = new int[2 * N][2 * N];
    static int[][] g = new int[2 * N][2 * N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            w[i] = in.nextInt();
            w[i + n] = w[i];
        }
        for (int i = 1; i <= 2 * n; i++) {
            s[i] = s[i - 1] + w[i];
        }
        for (int i = 2; i <= n; i++) {
            for (int l = 1; l + i - 1 <= 2 * n; l++) {
                int r = l + i - 1;
                f[l][r] = 0x3f3f3f3f;
                g[l][r] = -0x3f3f3f3f;
                for (int k = l; k < r; k++) {
                    f[l][r] = Math.min(f[l][r], f[l][k] + f[k + 1][r] + s[r] - s[l - 1]);
                    g[l][r] = Math.max(g[l][r], g[l][k] + g[k + 1][r] + s[r] - s[l - 1]);
                }
            }
        }
        int res1 = 0x3f3f3f3f, res2 = -0x3f3f3f3f;
        for (int i = 1; i <= n; i++) {
            res1 = Math.min(res1, f[i][i + n - 1]);
            res2 = Math.max(res2, g[i][i + n - 1]);
        }
        System.out.println(res1);
        System.out.println(res2);
    }
}
